//
//  SDDoctorApplyController.m
//  SuperDoctor
//
//  Created by 李忠 on 7/5/16.
//  Copyright © 2016 SD. All rights reserved.
//

#import "SDDoctorApplyController.h"
#import "SDApplyCell.h"
#import "NetWorkDefine.h"
#import "SDNetWorkTool.h"
#import "SDApplyModel.h"
#import "SDApplyInfoController.h"

@interface SDDoctorApplyController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong)NSArray * dataArray;

@end

@implementation SDDoctorApplyController

- (void)viewDidLoad {
    [super viewDidLoad];
	
	[self setupUI];
	
}

#pragma mark - 设置界面
//设置界面
- (void)setupUI {
	
	UITableView * applyView = [[UITableView alloc]initWithFrame:self.view.frame];

	
	[self.view addSubview:applyView];
	
	applyView.delegate = self;
	
	applyView.dataSource = self;
	
}

#pragma mark - 代理方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
	
	return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
	
	SDApplyCell * cell = [[SDApplyCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
	
	cell.model = self.dataArray[indexPath.row];
	
	cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
	
	return cell;
}

//设置行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
	return 100;
}

//点击cell跳转
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
	
	SDApplyInfoController * infoVC = [[SDApplyInfoController alloc]init];
	
	infoVC.model = self.dataArray[indexPath.row];
	
	[self.navigationController pushViewController:infoVC animated:YES];
	
	[tableView deselectRowAtIndexPath:indexPath animated:NO];
}



#pragma mark - 懒加载

- (NSArray *)dataArray{
	
	if (_dataArray == nil) {
		
		if (nil == _dataArray) {
			
			// 1. 获取文件路径
			NSString *path = [[NSBundle mainBundle] pathForResource:@"ApplyDoctor.plist" ofType:nil];
			
			// 2. 读取文件内容到临时数组
			NSArray *tempArray = [NSArray arrayWithContentsOfFile:path];
			
			
			// 3. 创建可变数组
			NSMutableArray *mutable = [NSMutableArray array];
			
			// 4/ 遍历 tempArray 中的字典, 给转为模型AppModel
			for (NSDictionary *dict in tempArray) {
				// 4.1 实例化一个模型对象
				//            AppModel *appModel = [[AppModel alloc] initWithDict:dict];
				
				SDApplyModel *appModel = [SDApplyModel modelWithDict:dict];
				
				// 4.3 把对象添加到可变数组中
				[mutable addObject:appModel];
				
			}
			
			// 5. 不要忘记, 把可变数组, 赋值给 _dataArray
			_dataArray = mutable;
			
		}

	}
	return _dataArray;
}


@end
